package cn.xm.basic.controller;

import cn.xm.basic.dto.AccountLoginDto;
import cn.xm.basic.dto.WechatBinderDto;
import cn.xm.basic.dto.WechatLoginDto;
import cn.xm.basic.service.LoginService;
import cn.xm.basic.util.AjaxResult;
import cn.xm.user.dto.PhoneRegisterDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private LoginService loginService;

    /**
     * 手机登录接口
     * @param dto
     * @return
     * @throws Exception
     */
    @PostMapping("/account")
    public AjaxResult accountLogin(@RequestBody @Valid AccountLoginDto dto) throws Exception {

        Map<String, Object> map = loginService.accountLogin(dto);
        return AjaxResult.me().success(map);
    }

    /**
     * 微信登录接口
     * @param dto
     * @return
     * @throws Exception
     */
    @PostMapping("/wechat")
    public AjaxResult wechatLogin(@RequestBody @Valid WechatLoginDto dto) throws Exception {

        return loginService.wechatLogin(dto);
    }

    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody @Valid WechatBinderDto dto) throws Exception {
        Map<String, Object> map = loginService.wechatBinder(dto);
        return AjaxResult.me().success(map);
    }

}
